#include "HttpSever.hpp"

int gdefaultport = 8888;
void Login(HttpRequest &req, HttpRespond &resp)
{
  LOG(LogLevel::DEBUG) << "进入登录模块" << req.Path() << ", " << req.Args();
  std::string req_args = req.Args();
  // 1. 解析参数格式，得到要的参数

  // 2. 访问数据库，验证对应的用户是否是合法的用户，其他工作....
  // TODO
  // SessionManager m;
  // session_id = m.CreateSession(XXXXX);

  // 3. 登录成功
  std::string body = req.GetContent("wwwroot/success.html");
  resp.SetCode(200);
  resp.SetHeader("Content-Length", std::to_string(body.size()));
  resp.SetHeader("Content-Type", "text/html");
  resp.SetHeader("Set-Cookie", "usename=zhangsan&passwd=11111111");
  resp.SetBody(body);
}
int main()
{

  auto httpserver = std::make_unique<HttpServer>(gdefaultport);
  //要先注册再启动服务器 要不注册不进去会阻塞住
  httpserver->Register("/login",Login);
  httpserver->Start();
  
  
  return 0;
}